//
//  ProblemCell.m
//  RENTVISITOR
//
//  Created by wonder on 2017/9/5.
//  Copyright © 2017年 UNN. All rights reserved.
//

#import "ProblemCell.h"
#import "RentVieitor.h"
#import "NewsModel.h"

@implementation ProblemCell {
    
    UILabel *introduce;
    UILabel *price;
    UILabel *dateLabel;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.selectionStyle = UITableViewCellEditingStyleNone;
        [self creatView];
    }
    return self;
}


- (void)creatView {
    
    __weak typeof(self) weakSelf = self;
    UIImageView *imgview = [[UIImageView alloc] init];
    imgview.image = [UIImage imageNamed:@"recomimg_01"];
    [self.contentView addSubview:imgview];
    
    [imgview mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(weakSelf.contentView.mas_centerY);
        make.left.mas_equalTo(weakSelf.contentView.mas_left).with.offset(15);
        make.size.mas_equalTo(CGSizeMake(110*Main_Scale, 80*Main_Scale));
    }];
    
    introduce = [[UILabel alloc] init];
    introduce.text = @"租房时令人头疼的问题都有哪些?";
    introduce.font = [UIFont systemFontOfSize:15*Main_Scale];
    introduce.textColor = [Utils colorConvertFromString:@"#101010"];
    introduce.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:introduce];
    
    [introduce mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(imgview.mas_right).with.offset(10);
        make.top.mas_equalTo(imgview.mas_top).with.offset(5);
        make.right.mas_equalTo(weakSelf.contentView.mas_right).with.offset(10);
        make.height.mas_equalTo(@(15*Main_Scale));
    }];
    
    price = [[UILabel alloc] init];
//    price.backgroundColor = [UIColor redColor];
    price.text = @"租房时常让人头疼,其中存在的问题很多.房屋面积不够大,环境不够好...";
    price.font = [UIFont systemFontOfSize:12*Main_Scale];
    price.numberOfLines = 0;
    [self changeLineSpaceForLabel:price WithSpace:5.0];
    price.textColor = [Utils colorConvertFromString:@"#666666"];
    price.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:price];
    
    [price mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(introduce.mas_bottom).with.offset(10);
        make.left.mas_equalTo(imgview.mas_right).with.offset(10);
        make.right.mas_equalTo(weakSelf.contentView.mas_right).with.offset(-10);
        
    }];
    
    dateLabel = [[UILabel alloc] init];
    dateLabel.text = @"2017-05-06";
    dateLabel.font = [UIFont systemFontOfSize:10];
    dateLabel.textColor = [Utils colorConvertFromString:@"#101010"];
    dateLabel.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:dateLabel];
    
    [dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.mas_equalTo(weakSelf.contentView.mas_bottom).with.offset(-10);
        make.right.mas_equalTo(weakSelf.contentView.mas_right).with.offset(-10);
    }];
}

- (void)setModel:(NewsModel *)model {
    
    _model = model;
    introduce.text = _model.title;
    price.text = _model.abstract;
    if ([_model.abstract isEqualToString:@""] || _model.abstract == nil) {
        price.text = @"租房时常让人头疼,其中存在的问题很多.房屋面积不够大,环境不够好...";
    }
    dateLabel.text = _model.date;
    
}

//改变行间距
- (void)changeLineSpaceForLabel:(UILabel *)label WithSpace:(float)space {
    
    NSString *labelText = label.text;
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:labelText];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:space];
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [labelText length])];
    label.attributedText = attributedString;
    [label sizeToFit];
    
}


@end
